// brandDetail.js
const regeneratorRuntime = require('../../lib/runtime');
const wx = require('../../lib/wx');
const Api = require('../../utils/api.js');
const wxapp = require('../../lib/wxapp');
const WxParse = require('../../wxParse/wxParse.js');

// 获取应用实例
const app = getApp();
Page({
  data: {
    filterActive: '综合',
    sortStatus: '',
    brandDetailBanner: '../../images/no_image.png',
    description:'简介',
    brandDetail: {
      list:[
        {
          imgUrl: '../../images/no_image.png',
          url: '../productDetail/productDetail',
          brandName: '品牌',
          description: '标题',
          currentprice: '00.00',
          orignprice: '00.00',
          shop: '品牌',
          people: 2,
          joined: 10,
        },

      ],
    },
    id:0
  },

  goToDetail: wxapp.handler(function* goToDetail(next, e){
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
    });

    yield next;
  }),

  goToMenu: wxapp.handler(function* goToMenu(next, e){
    const url = e.currentTarget.dataset.url;
    wx.reLaunch({
      url,
    });

    yield next;
  }),

  switchFilter: wxapp.handler(function* switchFilter(next, e) {
    const activeFilter = e.currentTarget.dataset.filter;
    const pageData = this.data;
    let sortStatus = pageData.sortStatus;
    if (activeFilter === '价格') {
      if(sortStatus === ''){
        sortStatus = 'up';
      } else if(sortStatus === 'up'){
        sortStatus = 'down';
      } else if(sortStatus === 'down'){
        sortStatus = 'up';
      }
    } else{
      sortStatus = '';
    }
    this.setData({
      sortStatus,
      filterActive: activeFilter,
    });

    var getSpecialDetail = Api.getSpecialDetail();
    var that = this;
    var getSpecialGoods = Api.getSpecialGoods();
    var id = this.data.id;console.log(id);
    wx.request({
      url: getSpecialGoods,
      header: {
        'content-type': 'application/json'
      },
      method: 'GET',
      data: {//发送给后台的数据
        id: id,
        sort: sortStatus
      },
      complete: function (res) {
        that.setData({
          brandDetail: res.data.data
        });
      }
    });

    yield next;
  }),

  onShow: wxapp.handler(function* onShow(next) {

    yield next;
  }),

  onLoad: wxapp.handler(function* onLoad(next, options) {
    const id = options.id;
    this.setData({
      id:id
    });
    var getSpecialDetail = Api.getSpecialDetail();
    var that = this;
    wx.request({
      url: getSpecialDetail,
      header: {
        'content-type': 'application/json'
      },
      method: 'GET',
      data: {//发送给后台的数据
        id: id
      },
      complete: function (res) {
        that.setData({ 
          brandDetailBanner:res.data.data.img,
          description: res.data.data.details
          });
        wx.setNavigationBarTitle({ title: res.data.data.name });
      }
    });

  var getSpecialGoods = Api.getSpecialGoods();
  wx.request({
    url: getSpecialGoods,
    header: {
      'content-type': 'application/json'
    },
    method: 'GET',
    data: {//发送给后台的数据
      id: id
    },
    complete: function (res) {
      that.setData({
        brandDetail:res.data.data
      });
    }
  });

    yield next;
  }),

});
